🧠 All Examples of Roblox LocalScript

LocalScripts run on the client side (player's computer). They are used for GUIs, camera control, player input, animations, and more.

1. 🔘 Detect Button Click (UI)

local button = script.Parent
button.MouseButton1Click:Connect(function()
  print("Button clicked!")
end)

2. 🏃‍♂️ Change Player WalkSpeed

local player = game.Players.LocalPlayer
player.CharacterAdded:Connect(function(char)
  char:WaitForChild("Humanoid").WalkSpeed = 50
end)

3. 📷 Camera Zoom Control

local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 120

4. 🎮 Key Press Detection

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
  if input.KeyCode == Enum.KeyCode.E then
    print("E key pressed!")
  end
end)

5. 🔄 Tweening UI (Animation)

local tweenService = game:GetService("TweenService")
local ui = script.Parent
local tween = tweenService:Create(ui, TweenInfo.new(1), {Position = UDim2.new(0.5, 0, 0.5, 0)})
tween:Play()

6. 🖱️ Mouse Hover on Part

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Move:Connect(function()
  if mouse.Target then
    print("Hovering on", mouse.Target.Name)
  end
end)

7. 🎵 Play a Sound

local sound = script.Parent:WaitForChild("Sound")
sound:Play()

8. ⌨️ TextBox Input

local textbox = script.Parent
textbox.FocusLost:Connect(function()
  print("Typed:", textbox.Text)
end)

9. 👁️ Show/Hide GUI

local frame = script.Parent:WaitForChild("MyFrame")
frame.Visible = false

wait(3)
frame.Visible = true

10. 🔁 Looping Text Label

local label = script.Parent
local messages = {"Loading.", "Loading..", "Loading..."}
while true do
  for _, msg in pairs(messages) do
    label.Text = msg
    wait(0.5)
  end
end
📘 Tutorial